<template>
  <div class="report-container">
    <h1>个人报告</h1>

    <div class="report-header">
      <div class="name-age">
        <span class="name">{{ name }}</span>
        <span class="age">{{ age }}</span>
      </div>
      <el-button class="edit-button" icon="el-icon-edit" @click="toggleEditMode">{{ editMode ? '保存' : '编辑' }}</el-button>
    </div>
    <el-form :model="form" ref="form" label-width="80px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="姓名">
             <div class="value" v-if="!editing">{{ form.name}}</div>
            <el-input v-model="form.name" v-if="!editing" placeholder="请输入姓名"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="年龄">
            <div class="value" v-if="!editing">{{ form.age}}</div>
            <el-input v-model="form.age" :v-if="!editing" placeholder="请输入年龄"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="性别">
            <div class="value" v-if="!editing">{{ form.gender}}</div>
            <el-radio-group v-model="form.gender" v-if="!editing">
              <el-radio label="male">男</el-radio>
              <el-radio label="female">女</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="血糖值">
            <div class="value" v-if="!editing">{{ form.bloodSugar}}</div>
            <el-input v-model="form.bloodSugar" v-if="!editing" placeholder="请输入血糖值"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div class="button-group">
      <el-button type="primary" v-if="!editing" @click="toggleEditing">编辑</el-button>
      <el-button type="success" v-else @click="submitForm">保存</el-button>
      <el-button type="default" v-if="editing" @click="cancelEdit">取消</el-button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        name: '',
        age: '',
        gender: '',
        bloodSugar: ''
      },
      editing: false
    }
  },
  methods: {
    toggleEditing() {
      this.editing = true;
    },
    cancelEdit() {
      this.editing = false;
      this.$refs.form.resetFields();
    },
    submitForm() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.editing = false;
          this.$message.success('保存成功');
        } else {
          this.$message.error('表单验证失败');
          return false;
        }
      });
    }
  }
}
</script>

<style scoped>
.report-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 30px;
  border: 1px solid #ddd;
}
.button-group {
  margin-top: 30px;
  text-align: right;
}
.report-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.name, .age {
  font-size: 24px;
  font-weight: bold;
}

.edit-button {
  padding: 0;
  font-size: 16px;
}

.report-content {
  margin-top: 20px;
  font-size: 16px;
  line-height: 1.5;
}
</style>
